package com.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @Date: 2019-12-12 15:56
 * @Author: CSP
 * @Description:
 */
@Configuration
@EnableSwagger2
public class Swagger2 {

    //api接口包扫描路径
//    public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.example.demo";
    public static final String SWAGGER_SCAN_BASE_PACKAGE = "/**";

    public static final String VERSION = "1.0.0";

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(true)
                // 接口文档的基本信息
                .apiInfo(apiInfo())
                .select()
                // 方法需要有ApiOperation注解才能生存接口文档
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))
                // 路径使用any风格
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("接口文档")
                .description("集成Swagger")
                .termsOfServiceUrl("http://blog.csdn.net/chen1218chen")
                .version(VERSION)
                .build();
    }

}